package cn.ffcs.uec.common.component;

import org.zkoss.zul.Treecell;
import org.zkoss.zul.Treeitem;
import org.zkoss.zul.TreeitemRenderer;
import org.zkoss.zul.Treerow;

import cn.ffcs.uec.common.vo.UecBdDefdoc;
import cn.ffcs.uom.common.treechooser.constants.Constants;
import cn.ffcs.uom.common.zkplus.zul.tree.node.impl.TreeNodeImpl;

public class UecBdDefdocTreeitemRenderer implements TreeitemRenderer {

    private UecBdDefdocTreeBandboxExt bandbox;

    public UecBdDefdocTreeitemRenderer(UecBdDefdocTreeBandboxExt bandbox) {
        this.bandbox = bandbox;
    }
    
    @SuppressWarnings("rawtypes")
    @Override
    public void render(Treeitem item, Object data) throws Exception {
        final TreeNodeImpl ite = (TreeNodeImpl) data;
        UecBdDefdoc  node = (UecBdDefdoc) ite.getEntity();

        // set checkable range
        if (Constants.RANGE_END.equals(bandbox.getRange())) {
            item.setCheckable(node.isEnd());
        }

        item.setValue(ite);
        item.setOpen(true);

        final Treecell tcNamn = new Treecell(ite.getLable());
        Treerow tr = null;
        if (item.getTreerow() == null) {
            tr = new Treerow();
            tr.setParent(item);
        } else {
            tr = item.getTreerow();
            tr.getChildren().clear();
        }
        tcNamn.setParent(tr);
        tcNamn.setStyle("white-space:nowrap;"); 
        
    }
}
